-
Notifications
You must be signed in to change notification settings - Fork 170
Add rendered HTML content support via Accept header #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Follow-up: I discovered Dataview/DataviewJS blocks were still empty unless the renderer had a real DOM host. The latest commit |
Implement DOM-based extraction of rendered Obsidian content with support for both plain text and structured JSON output formats. Features: - rendered-text content type: Plain text extraction from rendered DOM - rendered-json content type: Structured JSON with typed content blocks - Cache system for fast repeated access - Full Dataview/DataviewJS rendering support - Settings UI for cache configuration - Automatic cache invalidation on file changes Content Types: - application/vnd.olrapi.note+rendered-text (plain text) - application/vnd.olrapi.note+rendered-json (structured JSON) JSON Structure: - metadata: source path, render timestamp, format version - frontmatter: complete YAML frontmatter as object - content: array of typed blocks (heading, table, list, paragraph, code, callout) Table blocks include headers and rows as 2D arrays, making them easy to parse and analyze programmatically. Implementation: - RenderCacheManager: handles rendering and caching - StructuredExtractor: converts DOM to typed JSON blocks - Cache stored in .obsidian/render-cache/ with hash-based keys - 2-second content settlement wait for async plugin rendering - Restores original user view after extraction Benefits for AI Clients: - Tables as parseable 2D arrays - Document structure preserved with type tags - Frontmatter metadata accessible - Content queryable by type - No parsing ambiguity Testing: - Verified with complex Dataview dashboards - Tables extract correctly with headers and rows - All frontmatter fields preserved - Bundle size: 2.4mb (optimized, no PDF dependencies) 🤖 Generated with Claude Code https://claude.com/claude-code Co-Authored-By: Claude <noreply@anthropic.com>
Document the new rendered-text and rendered-json content types, including usage examples, JSON schema, caching system, and troubleshooting guide. - Updated README.md with rendered content overview - Added comprehensive RENDERED_CONTENT.md guide - Includes API reference, examples, and use cases - Documents both text and JSON output formats 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
coddingtonbear
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for the patch, @papertray3 — there are some great ideas here! I’m definitely open to supporting a feature that returns rendered HTML when the user supplies an appropriate Accept header (likely text/html, as I noted in a few comments).
I did notice that this PR bundles together a few larger changes that aren’t directly related to that HTML-rendering behavior. To keep things easy to review and to get your work merged more quickly, would you mind splitting this into smaller, focused PRs, each introducing a single change or feature? When you do, a quick update to the docs in /docs would also help people understand how to use the new functionality.
Once you’ve had a chance to break things out, feel free to ping me — I really appreciate the contribution, and I think the rendered-HTML feature in particular will be super useful to a lot of users!
|
|
||
| This was inspired by [Vinzent03](https://github.com/Vinzent03)'s [advanced-uri plugin](https://github.com/Vinzent03/obsidian-advanced-uri) with hopes of expanding the automation options beyond the limitations of custom URL schemes. | ||
|
|
||
| ## Rendered Content Support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have public docs in the /docs/ folder. Instead of documenting this in the readme, that should probably be in the docs themselves if you could.
| @@ -0,0 +1,540 @@ | |||
| # Rendered Content API | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm betting this is an artifact created when you asked an LLM to help you code this and I bet you didn't intend to include this in the PR.
| olrapiNoteJson = "application/vnd.olrapi.note+json", | ||
| olrapiNoteHtml = "application/vnd.olrapi.note+html", | ||
| olrapiRenderedText = "application/vnd.olrapi.note+rendered-text", | ||
| olrapiRenderedJson = "application/vnd.olrapi.note+rendered-json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgive me, but this PR is already extremely long -- could I trouble you to break this apart into individual PRs for each of these types of content? Only one of these content types appears to be discussed in this PR; so I think sticking to rendered HTML in this one is probably the right choice, and I want to say: I might need some convincing before I'll be up for taking on a patch for the other two rendering options.
Second thing: you don't need to invent a new content type for things like html/text/json -- those already exist:
text/htmltext/plainapplication/json
| ); | ||
|
|
||
| // Cache statistics | ||
| if (this.plugin.renderCacheManager) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a particular performance problem you found that inspired you to want to cache renders? It seems like kind of a lot of complication to add unless there are severe performance problems.
Summary
This PR adds support for retrieving rendered HTML content from markdown files using HTTP content negotiation. Clients can now request fully-rendered HTML by specifying
Accept: application/vnd.olrapi.note+htmlin GET requests.Changes
ContentTypes.olrapiNoteHtmlconstant (application/vnd.olrapi.note+html)renderMarkdownToHtml()method using Obsidian's nativeMarkdownRenderer.render()API_vaultGet()to handle HTML content type requestsFeatures
The rendered HTML output includes:
data-hrefattributesAPI Usage
Backward Compatibility
This feature:
/vault/,/active/,/periodic/)Testing
Tested with:
/vault/{filename}and/active/endpointsUse Cases
This feature enables:
🤖 Generated with Claude Code